/*     */ package com.engines;
/*     */ 
/*     */ import com.engine.Tools;
/*     */ import java.io.PrintStream;
/*     */ import java.sql.Connection;
/*     */ import java.sql.DriverManager;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ 
/*     */ public class DBEngine
/*     */ {
/*  12 */   private Connection conn = null;
/*  13 */   private static String FILE_CONFIG = "config/conf.props";
/*     */ 
/*  70 */   private Statement stmt = null;
/*     */ 
/*     */   public DBEngine()
/*     */   {
/*     */     try
/*     */     {
/*  19 */       Class.forName(Tools.readprops(FILE_CONFIG, "driver", "com.mysql.jdbc.Driver")).newInstance();
/*  20 */       initDB();
/*     */     }
/*     */     catch (Exception ex) {
/*  23 */       System.out.println(ex.getMessage());
/*     */     }
/*     */   }
/*     */ 
/*     */   private void initDB()
/*     */   {
/*     */     try {
/*  30 */       this.conn = DriverManager.getConnection(Tools.readprops(FILE_CONFIG, "header", "jdbc:mysql://localhost/simrs?user=root&password=password"));
/*  31 */       System.out.println("DB Connection OK");
/*     */     }
/*     */     catch (SQLException ex)
/*     */     {
/*  35 */       System.out.println("SQLException: " + ex.getMessage());
/*  36 */       System.out.println("SQLState: " + ex.getSQLState());
/*  37 */       System.out.println("VendorError: " + ex.getErrorCode());
/*     */     }
/*     */   }
/*     */ 
/*     */   public void setNotAutoCommit()
/*     */   {
/*     */     try {
/*  44 */       this.conn.setAutoCommit(false);
/*     */     }
/*     */     catch (SQLException ex) {
/*  47 */       System.out.println("SQLException: " + ex.getMessage());
/*  48 */       System.out.println("SQLState: " + ex.getSQLState());
/*  49 */       System.out.println("VendorError: " + ex.getErrorCode());
/*     */     }
/*     */   }
/*     */ 
/*     */   public void commit()
/*     */   {
/*     */     try {
/*  56 */       this.conn.commit();
/*     */     }
/*     */     catch (SQLException ex) {
/*  59 */       System.out.println("SQLException: " + ex.getMessage());
/*  60 */       System.out.println("SQLState: " + ex.getSQLState());
/*  61 */       System.out.println("VendorError: " + ex.getErrorCode());
/*     */     }
/*     */   }
/*     */ 
/*     */   public Connection getConnection()
/*     */   {
/*  67 */     return this.conn;
/*     */   }
/*     */ 
/*     */   public boolean execute(String strSQL)
/*     */   {
/*     */     try
/*     */     {
/*  75 */       this.stmt = this.conn.createStatement();
/*  76 */       this.stmt.executeUpdate(strSQL);
/*  77 */       close();
/*  78 */       return true;
/*     */     }
/*     */     catch (SQLException ex)
/*     */     {
/*  82 */       System.out.println("SQLException: " + ex.getMessage());
/*  83 */       System.out.println("SQLState: " + ex.getSQLState());
/*  84 */       System.out.println("VendorError: " + ex.getErrorCode());
/*  85 */     }return false;
/*     */   }
/*     */ 
/*     */   public ResultSet getSQL(String strSQL)
/*     */   {
/*  90 */     ResultSet rs = null;
/*     */     try {
/*  92 */       this.stmt = this.conn.createStatement();
/*  93 */       rs = this.stmt.executeQuery(strSQL);
/*     */     }
/*     */     catch (SQLException ex)
/*     */     {
/*  97 */       System.out.println("SQLException: " + ex.getMessage());
/*  98 */       System.out.println("SQLState: " + ex.getSQLState());
/*  99 */       System.out.println("VendorError: " + ex.getErrorCode());
/*     */     }
/*     */ 
/* 121 */     return rs;
/*     */   }
/*     */ 
/*     */   public void close()
/*     */   {
/* 126 */     if (this.stmt != null) {
/*     */       try {
/* 128 */         this.stmt.close(); } catch (SQLException localSQLException) {
/*     */       }
/* 130 */       this.stmt = null;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void close(ResultSet rs) {
/* 135 */     if (rs != null) {
/*     */       try {
/* 137 */         rs.close(); } catch (SQLException localSQLException) {
/*     */       }
/* 139 */       rs = null;
/*     */     }
/* 141 */     if (this.stmt != null) {
/*     */       try {
/* 143 */         this.stmt.close(); } catch (SQLException localSQLException1) {
/*     */       }
/* 145 */       this.stmt = null;
/*     */     }
/*     */   }
/*     */ }

/* Location:           F:\16 2\SQ.jar
 * Qualified Name:     com.engines.DBEngine
 * JD-Core Version:    0.6.0
 */